package functions;

import java.util.ArrayList;
import java.util.Iterator;

public class PaymentData implements java.io.Serializable{
	private ArrayList<SinglePayment> array;
	private double beginningBalance;
	
	public PaymentData(){
		this.array = new ArrayList<SinglePayment>();
		this.beginningBalance = 0;
	}
	
	public void addPayment(int month, int day, int year, double amount){
		this.array.add(new SinglePayment(month, day, year, amount));
	}

	public void removePayment(int index){
		this.array.remove(index);
	}
	
	public void insertPayment(int month, int day, int year, double amount, int index){
		this.array.add(index, new SinglePayment(month, day, year, amount));
	}
	
	public ArrayList<SinglePayment> getArray() {
		return array;
	}
	
	public double getBeginningBalance() {
		return beginningBalance;
	}

	public void setBeginningBalance(double beginningBalance) {
		this.beginningBalance = beginningBalance;
	}

	public double calculatePaymentSum(){
		double total = 0;
		Iterator<SinglePayment> it = this.array.iterator();
		while(it.hasNext()){
			total += it.next().getAmount();
		}
		return total;
	}
	
	public double calculateRemainingBalance(){
		return this.beginningBalance - calculatePaymentSum();
	}

}
